package cn.edu.xust.api.controller;


import cn.edu.xust.configuration.exception.Default200Exception;
import cn.edu.xust.configuration.exception.ErrorConstant;
import cn.edu.xust.entity.GatewayEntity;
import cn.edu.xust.entity.HotelEntity;
import cn.edu.xust.Ro.HotelBaseInfoRo;
import cn.edu.xust.Ro.hotelEnvRO.HotelEnvRo;
import cn.edu.xust.service.HotelService;
import cn.edu.xust.service.RoomService;
import cn.edu.xust.util.R;
import cn.edu.xust.util.ruoyi.StringUtils;
import cn.hutool.core.util.RandomUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.*;

@Slf4j
@CrossOrigin(allowCredentials = "true")
@RestController
@RequestMapping("/api/hotel")
public class ApiHotelController {

    @Autowired
    HotelService hotelService;


    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions(value={"29"},logical = Logical.OR)
    public R list() {
        List<HotelEntity> list = hotelService.list();
        return R.ok().put("data", list);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions(value={"29"},logical = Logical.OR)
    public R save(@RequestBody HotelEntity gateway) {
        //生成随机数作为appid appsec
        String s = RandomUtil.randomString(32);
        String s2 = RandomUtil.randomString(48);
        gateway.setAppid(s);
        gateway.setAppsec(s2);
        gateway.setCtime(new Date());
        hotelService.save(gateway);
        return R.ok();
    }


    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions(value={"29"},logical = Logical.OR)
    public R delete(@RequestBody HotelEntity gateway) {
        hotelService.removeById(gateway.getHotelId());

        return R.ok();
    }


}
